<template>
  <DiyButton>
    <template v-slot:opt>
      <div
        class="diy-button"
        @click="handleDismount"
        v-if="app.saleStatus === 1 && app.saleStatus === -1"
      >
        下架
      </div>
      <div class="diy-button" @click="handleDelete" v-else>
        删除
      </div>
    </template>
  </DiyButton>
</template>

<script>
import DiyButton from "@components/DiyButton/index";
import { mapGetters } from "vuex";
import { updateAppOffSale, checkRedeploy, deleteApp } from "@api/market";

export default {
  data() {
    return {};
  },
  components: {
    DiyButton,
  },
  props: ["app"],
  methods: {
    /**下架应用 */
    handleDismount() {
      let params = {
        ids: this.app.id,
      };
      updateAppOffSale(params).then((res) => {
        this.$emit("loadlistData");
        this.$message.success("下架成功");
      });
    },
    handleDelete(app) {
      this.$confirm("此操作将永久删除该应用, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let params = {
            appId: this.app.id,
          };
          deleteApp(params).then((res) => {
            console.log("params", params);
            this.$message.success('删除成功')
            this.$emit("loadlistData");
          });
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped></style>
